import java.util.Stack;

class MinStack {

    public Stack<Integer> stack;
    public Stack<Integer> minstack;
    public MinStack() {
        stack=new Stack<>();
        minstack = new Stack<>();
    }

    public void push(int x) {
        stack.push(x);
        if(minstack.isEmpty()){
            minstack.push(x);
            return;
        }
        if(x<=minstack.peek()){
            minstack.push(x);
        }
    }

    public void pop() {
        if(stack.isEmpty()){
            return;
        }
        int val=stack.pop();
        if(val==minstack.peek()){
            minstack.pop();
        }
    }

    public int top() {
        if(stack.isEmpty()){
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if(minstack.isEmpty()){
            return -1;
        }
        return minstack.peek();
    }

    public static void main1(String[] args) {
        MinStack minStack=new MinStack();
        minStack.push(512);
        minStack.push(-1024);
        minStack.push(-1024);
        minStack.push(512);
        minStack.pop();
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.getMin());
        minStack.pop();
        System.out.println(minStack.getMin());
    }

    public static void main(String[] args) {
        System.out.println("hello");
    }
}



